﻿using FilterIllegalCharacter.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace FilterIllegalCharacter.UI
{
    /// <summary>
    /// LocalDictMgt.xaml 的交互逻辑
    /// </summary>
    public partial class LocalDictMgt : Window
    {
        public LocalDictMgt()
        {
            InitializeComponent();
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // 加载本地词库
            textBoxWords.Text = string.Join("\r\n", DictFileHelper.ReadLocalDictFile());
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            // 写入本地词库
            DictFileHelper.WriteLocalDictFile(textBoxWords.Text.Split("\r\n").Where(x => !string.IsNullOrEmpty(x)).ToList());
            FilterHelper.Instance.ReInitDictionary(DictFileHelper.ReadAllDictFile());
            this.DialogResult = true;
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}
